<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	

</head>
<body>

	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" <c:if test="${User.type eq '2'  }"> style="text-align: -webkit-center;text-align: -moz-center;"</c:if>>
        <div class="row" id="test01">
            <div >
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>二维码管理</h5>

                    </div>
                    <div class="ibox-content">
                        <form action="${path}/qrcode/query" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label  class="sr-only">批次号</label>
                                <input type="text" placeholder="批次号" id="batch" name="batch" class="form-control">
                            </div>
                            <div class="form-group">
                                <label  class="sr-only">之前</label>
                                <input type="text" onclick="mylaydate(this.id)" name="enddate" placeholder="日期之前"  id="enddate"  class="form-control">
                            </div>
                            <div class="form-group">
                                <label  class="sr-only">之后：</label>
                                <input type="text" placeholder="日期之后" onclick="mylaydate(this.id)" id="startdate" name="startdate" class="form-control">
                            </div>


                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-reset" class="btn btn-warning">重置</button>
                            <button type="button" id="btn-add-k" class="btn btn-success fr">生成代金卷</button>
                            <button type="button" id="btn-add" class="btn btn-success fr" style="margin-right: 1%">生成二维码</button>

                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
            	url : "${path}/qrcode/query",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                   	id: "id", //相当于设置主键
		           	root: "result",//Json数据
		           	total: "allPage",//总页数
					page: "page", //当前页
					records: "allCount",//总记录数
					repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 30],
                colNames: ['编号','生成时间', '生成数量', ' 批次号','类型' , '操作'],
                colModel: [{
                        name: 'id',
                        index: 'id',
                        width: 20
                    },{
                        name: 'createDate',
                        index: 'createDate',
                        width: 30
                    },{
                        name: 'num',
                        index: 'num',
                        width: 25
                    },{
                        name: 'batch',
                        index: 'batch',
                        width: 15
                    },{
                    name: 'type',
                    index: 'type',
                    width: 15,
                    formatter:function(cellvalue, options, rowObject){
                        if (cellvalue==2){
                            return '<span style="color: green">代金卷</span>';
                        }else {
                            return '<span style="color: red">普通袋子二维码</span>';
                        }
                        return html;
                    }
                    },{
                        name: 'operator',
                        index: 'operator',
                        width: 35,
                        formatter:function(cellvalue, options, rowObject){
                        	var html = "<a class='btn btn-w-m btn-primary' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"down('"+rowObject.path +","+rowObject.folder+"')\">下载</a>";
                        	    // html += "<a class='btn btn-w-m btn-danger' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"del('"+rowObject.path+","+rowObject.folder+"')\">删除</a>";
                            return html;
                        }
                    }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: true
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");
            $("#btn-add").click(function(){
            	layer.open({
                    type: 2,
                    title: '生成二维码',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['600px', '400px'],
                    content: '${path}/qrcode/add' //iframe的url
                });
            });

            $("#btn-add-k").click(function(){
                layer.open({
                    type: 2,
                    title: '生成代金卷',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['600px', '400px'],
                    content: '${path}/qrcode/kimsvolume' //iframe的url
                });
            });
            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/qrcode/query",
                    datatype:'json',
                    postData : {
                    	"batch":$("#batch").val(),
                    	"enddate":$("#enddate").val(),
                        "startdate":$("#startdate").val()
                    }, 
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
        });
        function download(url){

        }
        function del(url){
        layer.msg("开发中....",{icon:7})
        }

        function down(url,folder) {
            var pfolder = url.split(",");
            var form = $("<form></form>").attr("action", '${path}/qrcode/download').attr("method", "POST");
            form.append($("<input></input>").attr("type", "hidden").attr("name", "pfolder").attr("value", pfolder[0]));
            form.append($("<input></input>").attr("type", "hidden").attr("name", "folder").attr("value", pfolder[1]));
            form.appendTo('body').submit().remove();

<%--            &lt;%&ndash;$.ajax({&ndash;%&gt; ajax 返回的字符型数据 不能下载--%>
            <%--    type: "POST",--%>
            <%--    url: "${path}/qrcode/download",--%>
            <%--    data:{"pfolder":pfolder[0],"folder":pfolder[1]},--%>
            <%--    dataType: "json",--%>
            <%--    success: function(json){--%>
            <%--        console.log(json);--%>
            <%--    }--%>

            <%--});--%>
        }





    </script>
</body>
</html>
